package Game;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class InputHandler implements KeyListener, FocusListener, MouseListener, MouseMotionListener {
	
		public boolean[] key = new boolean[68836];
        public int x;			public int y;
        public int draggedX;  	public int draggedY;
        public int pressedX; 	public int pressedY;
        
        
        public boolean inDrag = false;
        public void mouseMoved(MouseEvent e) {
                x=e.getX();
                y=e.getY();
        }
        public void mousePressed(MouseEvent e){
        	pressedX = e.getX();
        	pressedY = e.getY();
        	inDrag = true;
        }
        
    	public void mouseDragged(MouseEvent e) {
    		draggedX = e.getX();
    		draggedY = e.getY();	
    	}
    	
    	public void mouseReleased(MouseEvent e) {
    		inDrag = false;
    		pressedX = pressedY = draggedX = draggedY = 0;
    	}
    	
        public void focusLost(FocusEvent e) {
                for (int i = 0; i<key.length; i++) {
                        key[i] = false;
                }
        }
        
        public void keyPressed(KeyEvent e) {
                int keyCode = e.getKeyCode();
                if (keyCode > 0 && keyCode < key.length) {
                        key[keyCode] = true;
                }
        }
        
        public void keyReleased(KeyEvent e) {
                int keyCode = e.getKeyCode();
                if(keyCode > 0 && keyCode < key.length) {
                        key[keyCode] = false;
                }
        }

        public boolean isKeyDown(char a_keyToCheck)
        {
        	/*convert the char into a keyevent to find char's keycode*/
        	KeyEvent e;
        	e = new KeyEvent(null,0, 0, 0,0, a_keyToCheck);
        	int keyCode = e.getKeyCode();
        	
        	/* check to see if key at keycode is down */
            if(keyCode > 0 && keyCode < key.length) {
                    if(key[keyCode] == true)
                    	return true;
            }
            return false;
        }
		@Override
		public void mouseClicked(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseExited(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void focusGained(FocusEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void keyTyped(KeyEvent arg0) {
			// TODO Auto-generated method stub
			
		}
	

	
}
